/**
 * Copyright &copy; 2012-2016 <a href="https://istep.lczyfz.com">Istep</a> All rights reserved.
 */
package com.lczyfz.istep.modules.resource.service;

import com.lczyfz.istep.common.persistence.Page;
import com.lczyfz.istep.common.service.CrudService;
import com.lczyfz.istep.modules.resource.dao.ResourceCourseCoursesystemDao;
import com.lczyfz.istep.modules.resource.dao.ResourceTrainprogramCoursesystemDao;
import com.lczyfz.istep.modules.resource.entity.ResourceCourseCoursesystem;
import com.lczyfz.istep.modules.resource.entity.ResourceCoursesystem;
import com.lczyfz.istep.modules.resource.entity.ResourceTrainprogram;
import com.lczyfz.istep.modules.resource.entity.ResourceTrainprogramCoursesystem;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 课程-课程体系中间表Service
 * @author dh
 * @version 2017-02-21
 */
@Service
@Transactional(readOnly = true)
public class ResourceTrainprogramCoursesystemService extends CrudService<ResourceTrainprogramCoursesystemDao, ResourceTrainprogramCoursesystem> {


	public ResourceTrainprogramCoursesystem get(String id) {
		return super.get(id);
	}
	
	public List<ResourceTrainprogramCoursesystem> findList(ResourceTrainprogramCoursesystem resourceTrainprogramCoursesystem) {
		return super.findList(resourceTrainprogramCoursesystem);
	}
	
	public Page<ResourceTrainprogramCoursesystem> findPage(Page<ResourceTrainprogramCoursesystem> page, ResourceTrainprogramCoursesystem resourceTrainprogramCoursesystem) {
		return super.findPage(page, resourceTrainprogramCoursesystem);
	}
	
	@Transactional(readOnly = false)
	public void save(String duallist,ResourceTrainprogram resourceTrainprogram) {
		String[] resourceCoursesystemList = new String[0];
		if (duallist != null && !duallist.equals(""))
			resourceCoursesystemList = duallist.split(",");
		logger.debug("length: [{}]", resourceCoursesystemList.length);

		for (int i = 0; i < resourceCoursesystemList.length; i++) {

			ResourceTrainprogramCoursesystem resourceTrainprogramCoursesystem=new ResourceTrainprogramCoursesystem();
			resourceTrainprogramCoursesystem.setCoursesystemId(resourceCoursesystemList[i]);
			resourceTrainprogramCoursesystem.setTrainprogramId(resourceTrainprogram.getId());
			super.save(resourceTrainprogramCoursesystem);
		}


	}
	@Transactional(readOnly = false)
	public void update(String duallist,ResourceTrainprogram resourceTrainprogram) {
		ResourceTrainprogramCoursesystem  temp=new ResourceTrainprogramCoursesystem ();
		temp.setTrainprogramId(resourceTrainprogram.getId());
		List<ResourceTrainprogramCoursesystem> courseCoursesystemList=super.findList(temp);

		for(int i=0;i<courseCoursesystemList.size();i++)
		{
			super.delete(courseCoursesystemList.get(i));
		}
		String[] resourceCoursesystemList = new String[0];
		if (duallist != null && !duallist.equals(""))
			resourceCoursesystemList = duallist.split(",");
		logger.debug("length: [{}]", resourceCoursesystemList.length);
		for (int i = 0; i < resourceCoursesystemList.length; i++) {

			ResourceTrainprogramCoursesystem resourceTrainprogramCoursesystem=new ResourceTrainprogramCoursesystem();
			resourceTrainprogramCoursesystem.setCoursesystemId(resourceCoursesystemList[i]);
			resourceTrainprogramCoursesystem.setTrainprogramId(resourceTrainprogram.getId());
			super.save(resourceTrainprogramCoursesystem);
		}
	}
	@Transactional(readOnly = false)
	public void delete(ResourceTrainprogramCoursesystem resourceTrainprogramCoursesystem) {
		super.delete(resourceTrainprogramCoursesystem);
	}
	
}